package com.muyu.file.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.file.utils.HttpUtils;
import org.apache.http.HttpResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 人脸识别 FaceRecognitionController
 *
 * @author LeYang
 * on 2024/12/30
 */
@RestController
@RequestMapping("/face")
public class FaceRecognitionController {



    @PostMapping("/face")
    public Result faceRecognition(@RequestParam String image, @RequestParam String name, @RequestParam String idcard) {
        String host = "https://vidface.market.alicloudapi.com";
        String path = "/lundear/idface";
        String method = "POST";
        String appcode = "303fbf8dcc6b40dd8be310b9441d06ea";
        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "APPCODE " + appcode);
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

        Map<String, String> bodys = new HashMap<>();
        bodys.put("idcard", idcard);  // 使用传递的身份证号
        bodys.put("name", name);      // 使用传递的姓名
        bodys.put("image", image);    // 使用传递的图片（Base64编码的字符串）
        bodys.put("url", "url");      // URL可根据需要进行调整
        bodys.put("liveck", "0");

        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, new HashMap<>(), bodys);
            // 处理API返回的结果
            System.out.println(response.toString());
            return  Result.success(response.toString());  // 假设你有一个Result类来包装返回结果
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error( "API调用失败: " + e.getMessage());
        }
    }

}
